package com.molichuxing.services.infrastructure.service.impl;

import com.molichuxing.framework.utils.CollectionUtils;
import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.GroupDesenseMapper;
import com.molichuxing.services.infrastructure.dto.response.response.GroupDesenseDto;
import com.molichuxing.services.infrastructure.service.GroupDesenseService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service("groupDesenseService")
public class GroupDesenseServiceImpl implements GroupDesenseService {

    @Resource
    private GroupDesenseMapper groupDesenseMapper;

    @Override
    public List<GroupDesenseDto> getGroupDesenseListByParam(Map<String, Object> param) {
        return Convert.toGroupDesenseDtoList(groupDesenseMapper.getGroupDesenseListByParam(param));
    }

    /**
     * 批量添加
     * @param groupId
     * @param desenses
     * @return
     */
    @Override
    public int createBatchGroupDesense(int groupId, List<Integer> desenses) {
        if (groupId <= 0 || CollectionUtils.isEmpty(desenses)) {
            throw new IllegalArgumentException("param invalid groupId is :" +groupId+ "  desenses is : " +desenses);
        }
        return groupDesenseMapper.createBatchGroupDesense(groupId, desenses);
    }

    @Override
    public int deleteByGroupId(int groupId) {
        if (groupId <= 0) {
            throw new IllegalArgumentException("param invalid groupId is" +groupId);
        }

        return groupDesenseMapper.deleteByGroupId(groupId);
    }

    @Override
    public int deleteByDesenseId(int desenseId) {
        if (desenseId <= 0) {
            throw new IllegalArgumentException("param invalid desenseId is" +desenseId);
        }
        return groupDesenseMapper.deleteByDesenseId(desenseId);
    }
}
